package service

import (
	"errors"
	"gorm.io/gorm"
	"month/videosvr/internal/models"
)

func GetCommentAll(id int) (*models.VideoComment, error) {
	comment := new(models.VideoComment)
	return comment, models.InitMysql(func(DB *gorm.DB) error {
		res := DB.Where("id=?", id).First(&comment)
		if res.RowsAffected == 0 {
			return errors.New("无数据")
		}
		return nil
	})
}
func SaveComment(like int64) error {
	return models.InitMysql(func(DB *gorm.DB) error {
		return DB.Model(&models.VideoComment{}).Update("like", like).Error
	})
}

func CreateComment(comment models.VideoComment) error {
	return models.InitMysql(func(DB *gorm.DB) error {
		return DB.Create(&comment).Error
	})
}
